import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class StructInfo {
    public static void main(String[] args) {
        try {
            Class<?> rectangleClass = Class.forName("Rectangle");

            //　公有构造器
            Constructor<?>[] constructors = rectangleClass.getConstructors();
            for (Constructor<?> constructor : constructors) {
                System.out.println(constructor);
            }

            // 所有构造器
            Constructor<?>[] declaredConstructors = rectangleClass.getDeclaredConstructors();
            for (Constructor<?> declaredConstructor : declaredConstructors) {
                System.out.println(declaredConstructor);
            }

            // 获取父类
            Class<?> superclass = rectangleClass.getSuperclass();
            System.out.println(superclass);
            //　获取接口
            Class<?>[] interfaces = rectangleClass.getInterfaces();
            for (Class<?> inter : interfaces) {
                System.out.println(inter);
            }
            //　获取公有方法
            Method[] methods = rectangleClass.getMethods();
            for (Method method : methods) {
                System.out.println(method);
            }
            //　获取所有方法
            Method[] declaredMethods = rectangleClass.getDeclaredMethods();
            for (Method declaredMethod : declaredMethods) {
                System.out.println(declaredMethod);
            }
            //　或有公有属性
            Field[] fields = rectangleClass.getFields();
            for (Field field : fields) {
                System.out.println(field);
            }
            //　获取所有属性
            Field[] declaredFields = rectangleClass.getDeclaredFields();
            for (Field declaredField : declaredFields) {
                System.out.println(declaredField);
            }
            //　获取注解
            Annotation[] annotations = rectangleClass.getAnnotations();
            for (Annotation annotation : annotations) {
                System.out.println(annotation);
            }

            Annotation[] declaredAnnotations = rectangleClass.getDeclaredAnnotations();
            for (Annotation declaredAnnotation : declaredAnnotations) {
                System.out.println(declaredAnnotation);
            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
